import React, { Component } from 'react'
import { getSwiper } from 'api/home'
import { Swiper } from 'antd-mobile'
import { BASE_URL } from 'utils/url'

export default class SwiperCom extends Component {
  componentDidMount() {
    this.loadSwiper()
  }
  state = {
    swiper: [],
  }
  render() {
    return (
      <div>
        <Swiper autoplay>
          {this.state.swiper.map((item) => (
            <Swiper.Item key={item.id}>
              <div>
                <img src={BASE_URL + item.imgSrc} alt="" />
              </div>
            </Swiper.Item>
          ))}
        </Swiper>
      </div>
    )
  }
  loadSwiper = async () => {
    try {
      const { body: res } = await getSwiper()
      this.setState({
        swiper: res,
      })
    } catch (err) {
      console.dir(err)
    }
  }
}
